package cn.lingyangwl.agile.auth.model.mq;

import cn.lingyangwl.agile.auth.constants.AuthCons;
import cn.lingyangwl.agile.model.module.mq.AbstractMQ;
import cn.lingyangwl.agile.model.module.mq.BaseMqPayload;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

/**
 * 登录日志消息
 *
 * @author shenguangyang
 */
public class LoginLogMQ extends AbstractMQ  {
    public static final String QUEUE = "auth.login_log";
    public static final String EXCHANGE = AuthCons.EXCHANGE;
    public static final String KEY = "";

    public LoginLogMQ(MsgPayload msgPayload) {
        super(msgPayload);
    }

    /**
     * 定义Msg消息载体
     */
    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class MsgPayload extends BaseMqPayload {
        /**
         * 登录id
         */
        private String loginId;

        /**
         * 客户端id
         */
        private String clientId;

        /**
         * 用户名
         */
        private String userName;

        /**
         * 状态
         */
        private String status;

        /**
         * 消息
         */
        private String message;

        /**
         * 耗时
         */
        private Long costTime;

        /**
         * 租户id
         */
        private String tenantId;

        /** ip */
        private String ip;

        /** 地点 */
        private String location;

        /** 用户系统 */
        private String os;

        /** 浏览器 */
        private String browser;
    }

    public static LoginLogMQ build(MsgPayload payload) {
        if (StringUtils.isNotEmpty(payload.getMessage())) {
            payload.setMessage(StringUtils.substring(payload.getMessage(),  0, 500));
        }
        return new LoginLogMQ(payload);
    }
}
